public class Hanoi {
    public static void hanoi(int n, char pos1, char pos2, char pos3) {
        if (n == 1) {
            move(pos1, pos3);
        }
        else {
            hanoi(n-1, pos1, pos3, pos2);
            move(pos1, pos3);
            hanoi(n-1, pos2, pos1, pos3);
        }
    }

    public static void move(char pos1, char pos3) {
        System.out.print(pos1 + "->" + pos3 + " ");
    }

    public static void main(String[] args) {
        int num = 3;
        char pos1 = 'A';
        char pos2 = 'B';
        char pos3 = 'C';
        hanoi(num, 'A', 'B', 'C');
        move('A', 'C');
    }
}
